package com.xigua._树;

import com.xigua.TreeNode;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/4/123:35
 */
public class _617_合并二叉树 {



    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
        TreeNode ans = new TreeNode();
        if (root1 != null && root2!= null){
            ans.val = root1.val+root2.val;
            ans.left = mergeTrees(root1.left,root2.left);
            ans.right = mergeTrees(root1.right,root2.right);
        }else if (root1 == null && root2 == null){
            return null;
        }else if (root1 == null){
            return root2;
        }else {
            return root1;
        }
        return ans;

    }
}
